package com.yifi.common.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HttpSetHeader {

	public static void get(HttpServletResponse response)
	{
		response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Credentials", "true");
        response.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH");
        response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type,Token,Accept, Connection, User-Agent, Cookie");
        response.setHeader("Access-Control-Max-Age", "3628800");
	}
	public static void get(HttpServletResponse response,HttpServletRequest request)
	{
		/*
        String origin=request.getHeader("Origin");
        response.addHeader("Access-Control-Allow-Origin", origin);
        */
		response.setHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Credentials", "true");
        response.addHeader("Access-Control-Allow-Methods","*"); //使用通配符
        response.addHeader("Access-Control-Allow-Headers","*");  //使用通配符
		/*String token= TokenCache.get(code);
		String refresh_token= TokenCache.get(code+"_refresh");
		if(token==null) {
			renderJson(Response.fail("code过期，置换token失败！"));
		}else {
			renderJson(Response.ok("token", token).set("refresh_token", refresh_token));
		}*/
	}
	
	
	public static String getLocalUrl(HttpServletRequest request)
	{
		String path = request.getContextPath();
		String httpheader = request.getScheme();

		String local = httpheader + "://" + request.getServerName()+":"+request.getLocalPort()+path;
		
		return local;
	}
}
